package ru.usu.gv.uicomponents;

import ru.usu.gv.uicomponents.viewitems.vertex.BoxView;
import ru.usu.gv.uicomponents.viewitems.vertex.ConeView;
import ru.usu.gv.uicomponents.viewitems.vertex.CylinderView;
import ru.usu.gv.uicomponents.viewitems.vertex.IVertexViewItem;
import ru.usu.gv.uicomponents.viewitems.vertex.LODSphereView;
import ru.usu.gv.uicomponents.viewitems.vertex.SphereView;

import javax.media.j3d.Appearance;
import javax.media.j3d.TransformGroup;

import java.util.List;

/**
 * @author spupyrev
 * 02.11.2008
 */
public class UIVertexTypeRegistry extends UIViewTypeRegistry<IUIVertexType>
{
    private static abstract class UIVertexType extends UIViewType implements IUIVertexType
    {
        public UIVertexType(String id, String title, String icon)
        {
            super(id, title, icon);
        }
    }

    private static final UIVertexTypeRegistry instance = new UIVertexTypeRegistry();

    private UIVertexTypeRegistry()
    {
        addType(new UIVertexType("sphere", "Шар", "images/node.png")
        {
            public IVertexViewItem createVertexViewItem(Appearance appearance, TransformGroup transformGroup)
            {
                return new SphereView(appearance, transformGroup);
            }
        });

        addType(new UIVertexType("lodsphere", "Шар (lod)", "images/node.png")
        {
            public IVertexViewItem createVertexViewItem(Appearance appearance, TransformGroup transformGroup)
            {
                return new LODSphereView(appearance, transformGroup);
            }
        });

        addType(new UIVertexType("box", "Куб", "images/cube.png")
        {
            public IVertexViewItem createVertexViewItem(Appearance appearance, TransformGroup transformGroup)
            {
                return new BoxView(appearance, transformGroup);
            }
        });

        addType(new UIVertexType("cone", "Конус", "images/cone.png")
        {
            public IVertexViewItem createVertexViewItem(Appearance appearance, TransformGroup transformGroup)
            {
                return new ConeView(appearance, transformGroup);
            }
        });

        addType(new UIVertexType("cylinder", "Цилиндр", "images/column.png")
        {
            public IVertexViewItem createVertexViewItem(Appearance appearance, TransformGroup transformGroup)
            {
                return new CylinderView(appearance, transformGroup);
            }
        });
    }

    public static IVertexViewItem createVertexViewItem(String vertexTypeId, Appearance appearance, TransformGroup branchGroup)
    {
        IUIVertexType vertexType = findVertexType(vertexTypeId);
        return vertexType.createVertexViewItem(appearance, branchGroup);
    }

    public static List<String> getVertexTypeIds()
    {
        return instance.getViewTypeIds();
    }

    public static IUIVertexType findVertexType(String vertexTypeId)
    {
        return instance.findViewType(vertexTypeId);
    }
}
